package com.redrose.camera.base;

import android.os.Bundle;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.ViewModelProvider;

public abstract class BaseActivity<T extends ViewDataBinding> extends AppCompatActivity {
    protected T mBinding;
    protected AppViewModel mAppViewModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mAppViewModel = new ViewModelProvider(this,
                new ViewModelProvider.AndroidViewModelFactory(getApplication())).get(AppViewModel.class);
        mBinding = DataBindingUtil.setContentView(this, getLayoutId());
        initView();
        initConfigs();
        initObserver();
    }

    protected abstract void initObserver();

    protected abstract void initConfigs();

    protected abstract void initView();

    @LayoutRes
    protected abstract int getLayoutId();

    protected AppViewModel getAppViewModel() {
        return mAppViewModel;
    }
}
